<template>
  <router-view />
</template>
<script>
export default {
  data() {
    return {
      data: "",
      apiUrl: "",
    };
  },
  beforeMount() {
    this.apiUrl = localStorage.getItem("apiUrl");
  },
  computed: {
    listenApiUrl() {
      return this.apiUrl;
    },
  },
  watch: {
    listenApiUrl: function () {
      if (!this.apiUrl) {
        this.$router.push("/Auth/setApiUrl");
      }
    },
  },
  mounted() {
    this.setData();
  },
  methods: {
    //验证凭证
    tokenverify: function () {
      if (!this.apiUrl) {
        this.$router.push("/Auth/setApiUrl");
      }
      return new Promise((resolve) => {
        var token = localStorage.getItem("token");
        // console.log(token,'tokenverify')
        if (token) {
          this.setData();
          // console.log('this.setData();')
        } else {
          this.$router.push("/Auth/login");
          return;
        }
        var userid = this.data.aid;
        if (!token || !userid) {
          this.$router.push("/Auth/login");
          // window.console.log(userid, "!token || !userid");
        } else {
          const url = "/Admin/verifytoken";
          const paramObj = {
            token: localStorage.getItem("token"),
          };
          this.$server.sl("GET", url, paramObj).then((res) => {
            if (res.code == 4001) {
              this.$router.push("/Auth/login");
              this.$message.warning("凭证失效，请重新登陆");
              localStorage.clear();
              resolve(false);
            } else {
              resolve(true);
            }
          });
        }
      });
    },

    setData: function () {
      if (localStorage.getItem("data")) {
        this.data = JSON.parse(localStorage.getItem("data"));
        this.$store.commit("updatedata", this.data);
        // window.console.log(this.data);
      }
    },
  },
};
</script>
<style>
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
.mt1r {
  margin-top: 1rem;
}
.mr1r {
  margin-right: 1rem;
}
.ml1r {
  margin-left: 1rem;
}
.cursor-pointer {
  cursor: pointer;
}
.disflex {
  display: flex;
}
@import "assets/css/main.css";
</style>
